package com.huike.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.dto.BusinessDto;
import com.huike.dto.domain.TbBusiness;
import com.huike.mapper.BusinessPoolMapper;
import com.huike.mapper.CluePoolMapper;
import com.huike.result.PageResult;
import com.huike.service.BusinessPoolService;
import com.huike.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class BusinessPoolServiceImpl extends ServiceImpl<BusinessPoolMapper, TbBusiness> implements BusinessPoolService {
    private final CluePoolMapper cluePoolMapper;
    private final static String BEGIN="beginCreateTime";
    private final static String END="endCreateTime";
    private static final String FALSE_STATUS="3";//伪商机


    @Override
    public PageResult getBusinessPoolListPage(BusinessDto businessDto) {
        Page<TbBusiness> page = new Page<>(businessDto.getPageNum(), businessDto.getPageSize());
        LambdaQueryWrapper<TbBusiness> wrapper = new LambdaQueryWrapper<>();
        String beginCreateTime = businessDto.getParams().get(BEGIN);
        String endCreateTime = businessDto.getParams().get(END);
        wrapper.eq(businessDto.getId()!=null,TbBusiness::getClientId,businessDto.getId());
        wrapper.eq(StringUtils.isNotEmpty(businessDto.getPhone()),TbBusiness::getPhone,businessDto.getPhone());
        wrapper.eq(StringUtils.isNotEmpty(businessDto.getName()),TbBusiness::getName,businessDto.getName());
        wrapper.eq(TbBusiness::getStatus,FALSE_STATUS);

        if (StringUtils.isNotEmpty(beginCreateTime)&&StringUtils.isNotEmpty(endCreateTime)) {
            wrapper.between(TbBusiness::getCreateTime, beginCreateTime, endCreateTime);
        }
        Page<TbBusiness> res = super.page(page, wrapper);
        return new PageResult(res.getTotal(),res.getRecords());
    }
}
